package com.zhxymm.book.controllers;

import com.zhxymm.book.dao.NewBookRepository;
import com.zhxymm.book.entity.NewBook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import java.util.List;

@Controller
public class HomeController {

    @Value("${version}")
    private String version;

    @Autowired
    NewBookRepository newBookRepository;

    @GetMapping("/")
    public String displayHome(Model model){

        model.addAttribute("versionNumber",version);

        List<NewBook> newBooks = newBookRepository.findAll();
        model.addAttribute("newBooks",newBooks);
        return "main/home";
    }
}
